package hotel.action;

import hotel.service.ServiceManager;
import hotel.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
 * This class Delete User from DataBase
 * @author Alex
 *
 */
public class DeleteUserAction extends Action
{
	private static final Logger logger = Logger.getLogger(DeleteUserAction.class);
	private static final String DELETEUSERACTION_ERROR = "Error in DeleteUserAction:";
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
		    throws Exception 
		    {
				String mapper = ForwardActionTo.ERROR;
				int id;
				try
				{
					UserService userService = ServiceManager.getDefault().getUserService();
					id = Integer.valueOf(request.getParameter("id"));
					userService.deleteUser(id);
					mapper = ForwardActionTo.SUCCESS;
				}
				catch(NullPointerException e)
				{
					logger.error(DELETEUSERACTION_ERROR + e);
			 	}

				return mapping.findForward(mapper);
		    }
}
